/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.embed.infra.utils;

import org.cshoo.tattoo.embed.infra.entity.BaseEntity;
import org.cshoo.tattoo.embed.infra.entity.BaseRelation;

import java.util.Date;

/**
 * @author 杨翼
 * @since 1.0
 */
public class AuditFieldsUtils {

    /**
     * 新增时设置的审计字段
     *
     * @param baseEntity 实体对象
     */
    public static void setAddAuditFields(BaseEntity baseEntity) {
        Date now = new Date();
        baseEntity.setCreateTime(now);
        baseEntity.setLastUpdateTime(now);
        baseEntity.setCreatedBy(UserUtils.getUser().getUsername());
        baseEntity.setLastUpdatedBy(UserUtils.getUser().getUsername());
    }

    /**
     * 新增时设置的审计字段
     *
     * @param baseRelation 关系对象
     */
    public static void setAddAuditFields(BaseRelation baseRelation) {
        Date now = new Date();
        baseRelation.setCreateTime(now);
        baseRelation.setCreatedBy(UserUtils.getUser().getUsername());
    }

    /**
     * 修改时设置的审计字段
     *
     * @param baseEntity 实体对象
     */
    public static void setUpdateAuditFields(BaseEntity baseEntity) {
        Date now = new Date();
        baseEntity.setLastUpdateTime(now);
        baseEntity.setLastUpdatedBy(UserUtils.getUser().getUsername());
    }
}
